package com.usian.behavior.service.impl;

import com.usian.behavior.entity.ApFollowBehavior;
import com.usian.behavior.mapper.ApFollowBehaviorMapper;
import com.usian.behavior.service.IApFollowBehaviorService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.usian.common.enums.AppHttpCodeEnum;
import com.usian.common.exception.LeadException;
import com.usian.model.behavior.dtos.FollowBehaviorDto;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * <p>
 * APP关注行为表 服务实现类
 * </p>
 *
 * @author usian
 * @since 2022-07-18
 */
@Service
public class ApFollowBehaviorServiceImpl extends ServiceImpl<ApFollowBehaviorMapper, ApFollowBehavior> implements IApFollowBehaviorService {

    @Override
    public void saveFollowBehavior(FollowBehaviorDto dto) {

        //组装关注行为对象，保存到数据库中
        ApFollowBehavior apFollowBehavior = new ApFollowBehavior();
        apFollowBehavior.setApUserId(dto.getUserId());
        apFollowBehavior.setArticleId(dto.getArticleId());
        apFollowBehavior.setFollowId(dto.getFollowId());
        apFollowBehavior.setCreatedTime(new Date());
        apFollowBehavior.setUpdateTime(new Date());
        boolean b = this.save(apFollowBehavior);
        if(!b){
            throw new LeadException(AppHttpCodeEnum.SERVER_ERROR);
        }
    }
}
